{include file="public/layout" /}
<body>
<link rel="stylesheet" href="__SKIN__/css/page.css" media="all">
<div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-row">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="web-system">
                    <div class="layui-tab layui-tab-card">
                        {if condition="$Request.param.tabase != 1"}
                        <ul class="layui-tab-title">
                            <li><a href="{:url('form/index')}">报名信息管理</a></li>
                            <li><a href="{:url('Form/attr_index')}">报名表单管理</a></li>
                            <li class="layui-this"><a href="{:url('Form/config')}">报名提醒管理</a></li>
                        </ul>
                        {/if}

                        <div class="baoming-cate pt20 pl15">
                            提醒：您可以为客户报名信息设置接收人，建议您务必设置接收人信息，防止消息遗漏造成损失。
                        </div>
                        <div class="layui-form">
                            <div class="layui-tab-content" style="padding:10px 0">
                                <div class="layui-tab-item layui-show">
                                    <div class="layui-row layui-col-space15">
                                        <div class="layui-col-md12">
                                            <div class="layui-card">
                                                <div class="layui-card-body" pad15>
                                                    <div class="layui-form layui-border-box layui-table-view house-table">
                                                        <div class="layui-table-box">
                                                            <div class="layui-table-body " >
                                                                <table cellspacing="0" cellpadding="0" border="0" class="layui-table layui-form" style="width: 100%" lay-skin="line">
                                                                    <thead >
                                                                    <tr>
                                                                        <th class="wauto">
                                                                            <div class="layui-table-cell wauto tl">
                                                                                <input type="checkbox" lay-filter="checkAll" class="checkAll" lay-skin="primary" >
                                                                                消息提醒人
                                                                            </div>
                                                                        </th>
                                                                        <th class="w150 tc">
                                                                            <div class="layui-table-cell w150 tl" >
                                                                                <input type="checkbox" lay-filter="noteAll" class="noteAll" lay-skin="primary" >
                                                                                短信
                                                                            </div>
                                                                        </th>
                                                                        <th class="w150 tc">
                                                                            <div class="layui-table-cell w150 tl" >
                                                                                <input type="checkbox" lay-filter="emailAll" class="emailAll" lay-skin="primary" >
                                                                                邮箱
                                                                            </div>
                                                                        </th>
                                                                    </tr>
                                                                    </thead>
                                                                    <tbody>
                                                                    <tr>
                                                                        <td>
                                                                            <div class="layui-table-cell wauto tl">
                                                                                <input type="hidden" name="role[]" value="1">
                                                                                <input type="checkbox" name="person[]" id="person_1" {notempty name="$list[1]['person']"}checked="checked"{/notempty} value="1" lay-filter="person" lay-skin="primary">
                                                                                网站管理员
                                                                            </div>
                                                                        </td>
                                                                        <td>
                                                                            <div class="layui-table-cell w150 tl">
                                                                                <input type="checkbox" name="note[]"  id="note_1" {notempty name="$list[1]['note']"}checked="checked"{/notempty} value="1" lay-filter="note" lay-skin="primary">
                                                                            </div>
                                                                        </td>
                                                                        <td>
                                                                            <div class="layui-table-cell w150 tl">
                                                                                <input type="checkbox" name="email[]"  id="email_1" {notempty name="$list[1]['email']"}checked="checked"{/notempty} value="1" lay-filter="email" lay-skin="primary">
                                                                            </div>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <div class="layui-table-cell wauto tl">
                                                                                <input type="hidden" name="role[]" value="2">
                                                                                <input type="checkbox" name="person[]"  id="person_2" {notempty name="$list[2]['person']"}checked="checked"{/notempty} value="2" lay-filter="person" lay-skin="primary">
                                                                                所属经纪人
                                                                            </div>
                                                                        </td>
                                                                        <td>
                                                                            <div class="layui-table-cell w150 tl">
                                                                                <input type="checkbox" name="note[]"  id="note_2" {notempty name="$list[2]['note']"}checked="checked"{/notempty} value="2" lay-filter="note" lay-skin="primary">
                                                                            </div>
                                                                        </td>
                                                                        <td>
                                                                            <div class="layui-table-cell w150 tl">
                                                                                <input type="checkbox" name="email[]"  id="email_2" {notempty name="$list[2]['email']"}checked="checked"{/notempty} value="2" lay-filter="email" lay-skin="primary">
                                                                            </div>
                                                                        </td>
                                                                    </tr>
                                                                    </tbody>
                                                                </table>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit="" lay-filter="formSubmit">保存</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    layui.config({
        base: '__SKIN__/' //静态资源所在路径
        ,version: '{$version}'
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$
            ,element = layui.element
            ,layer = layui.layer
            ,form = layui.form;
        element.render();
        /* 触发事件 */
        var active = {
        };
        $('#LAY-component-layer-list .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] && active[type].call(this);
        });
        // 监听复选框全选
        form.on('checkbox(checkAll)', function(data){
            if (data.elem.checked) {
                $('.checkAll').attr('checked', true);
                $('.noteAll').attr('checked', true);
                $('.emailAll').attr('checked', true);
                $('input[name*=person]').attr('checked', true);
                $('input[name*=note]').attr('checked', true);
                $('input[name*=email]').attr('checked', true);
            } else {
                $('.checkAll').attr('checked', false);
                $('.noteAll').attr('checked', false);
                $('.emailAll').attr('checked', false);
                $('input[name*=person]').attr('checked', false);
                $('input[name*=note]').attr('checked', false);
                $('input[name*=email]').attr('checked', false);
            }
            form.render('checkbox');
        });
        //短信全选
        form.on('checkbox(noteAll)', function(data){
            if (data.elem.checked) {
                $('.noteAll').attr('checked', true);
                $('input[name*=note]').attr('checked', true);
            } else {
                $('.noteAll').attr('checked', false);
                $('input[name*=note]').attr('checked', false);
            }
            if (data.elem.checked && $('input[name*=person]:checked').length == $('input[name*=person]').length && $('input[name*=note]:checked').length == $('input[name*=note]').length && $('input[name*=email]:checked').length == $('input[name*=email]').length) {
                $('.checkAll').attr('checked', true);
            } else {
                $('.checkAll').attr('checked', false);
            }
            form.render('checkbox');
        });
        //邮箱全选
        form.on('checkbox(emailAll)', function(data){
            if (data.elem.checked) {
                $('.emailAll').attr('checked', true);
                $('input[name*=email]').attr('checked', true);
            } else {
                $('.emailAll').attr('checked', false);
                $('input[name*=email]').attr('checked', false);
            }
            if (data.elem.checked && $('input[name*=person]:checked').length == $('input[name*=person]').length && $('input[name*=note]:checked').length == $('input[name*=note]').length && $('input[name*=email]:checked').length == $('input[name*=email]').length) {
                $('.checkAll').attr('checked', true);
            } else {
                $('.checkAll').attr('checked', false);
            }
            form.render('checkbox');
        });
        //消息管理员
        form.on('checkbox(person)', function(data){
            if (data.elem.checked) {
                $('#'+data.elem.id).attr('checked', true);
                $('#note_'+data.value).attr('checked', true);
                $('#email_'+data.value).attr('checked', true);
            } else {
                $('#'+data.elem.id).attr('checked', false);
                $('#note_'+data.value).attr('checked', false);
                $('#email_'+data.value).attr('checked', false);
            }
            if (data.elem.checked && $('input[name*=note]:checked').length == $('input[name*=note]').length ){
                $('.noteAll').attr('checked', true);
            }else{
                $('.noteAll').attr('checked', false);
            }
            if (data.elem.checked && $('input[name*=email]:checked').length == $('input[name*=email]').length ){
                $('.emailAll').attr('checked', true);
            }else{
                $('.emailAll').attr('checked', false);
            }
            if (data.elem.checked && $('input[name*=person]:checked').length == $('input[name*=person]').length && $('input[name*=note]:checked').length == $('input[name*=note]').length && $('input[name*=email]:checked').length == $('input[name*=email]').length) {
                $('.checkAll').attr('checked', true);
            } else {
                $('.checkAll').attr('checked', false);
            }
            form.render('checkbox');
        });
        // 短信单选
        form.on('checkbox(note)', function(data){
            if (data.elem.checked && $('input[name*=note]:checked').length == $('input[name*=note]').length) {
                $('.noteAll').attr('checked', true);
            } else {
                $('.noteAll').attr('checked', false);
            }
            if (data.elem.checked && $('#email_'+data.value)[0].checked == true){
                $('#person_'+data.value).attr('checked', true);
            }else{
                $('#person_'+data.value).attr('checked', false);
            }
            if (data.elem.checked && $('input[name*=person]:checked').length == $('input[name*=person]').length && $('input[name*=note]:checked').length == $('input[name*=note]').length && $('input[name*=email]:checked').length == $('input[name*=email]').length) {
                $('.checkAll').attr('checked', true);
            } else {
                $('.checkAll').attr('checked', false);
            }
            form.render('checkbox');
        });
        //邮箱单选
        form.on('checkbox(email)', function(data){
            if (data.elem.checked && $('input[name*=email]:checked').length == $('input[name*=email]').length) {
                $('.emailAll').attr('checked', true);
            } else {
                $('.emailAll').attr('checked', false);
            }
            if (data.elem.checked && $('#note_'+data.value)[0].checked == true){
                $('#person_'+data.value).attr('checked', true);
            }else{
                $('#person_'+data.value).attr('checked', false);
            }
            if (data.elem.checked && $('input[name*=person]:checked').length == $('input[name*=person]').length && $('input[name*=note]:checked').length == $('input[name*=note]').length && $('input[name*=email]:checked').length == $('input[name*=email]').length) {
                $('.checkAll').attr('checked', true);
            } else {
                $('.checkAll').attr('checked', false);
            }
            form.render('checkbox');
        });
        //监听提交
        form.on('submit(formSubmit)', function(data){
            var load = layer_loading();
            data.field._ajax = 1;
            $.ajax({
                type : 'post',
                url : "{:url('Form/config')}",
                data : data.field,
                dataType : 'json',
                success : function(res){
                    layer.close(load); //关闭loading
                    if(res.code == 1){
//                        parent.window.location.href = res.url;
                    }else{
                        layer.msg(data.msg, {icon: 2,time: 2000});
                    }
                },
                error: function(e){
                    layer.close(load); //关闭loading
                    showErrorAlert();
                }
            });
            return false;
        });
    });

</script>

{include file="public/footer" /}